//
//  ViewController.swift
//  LunchDecider
//
//  Created by 王阳 on 2017/5/5.
//  Copyright © 2017年 WayneStudio. All rights reserved.
//

import UIKit
import Foundation
import AVFoundation

class ViewController: UIViewController {

    @IBOutlet weak var decideButton: UIButton!
    var dataArray = [(id: Int, name: String)]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        NetworkManager.requestData(.get, URLString: "http://localhost:8080/", parameters: ["foos":["f1","f3"],"foo":"f2"]) { (result) in
            print(result)
        }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.dataArray = SQLiteManager.sharedInstance.selectAll()
    }
    
    @IBAction func decideButtonClick(_ sender: Any) {
        let index: Int = Int(arc4random_uniform(UInt32(self.dataArray.count)))
        let name: String = self.dataArray[index].name
        self.decideButton.setTitle(name, for: .normal)
        
        //朗读
//        let utterance = AVSpeechUtterance.init(string: "今天要吃:" + name)
//        utterance.voice = AVSpeechSynthesisVoice(language: "zh-CN")
//        utterance.rate = 0.5
//        let synthesizer = AVSpeechSynthesizer()
//        synthesizer.speak(utterance)
    }
}

